package com.kamistoat.meimeimall.meimeimallpayment.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class PaymentThreadConfig {
    /**
     * 用于对账时将第三方订单刷到数据库的线程池.
     * IO等待时间长，大线程池。
     */
    @Bean("flushBillThreadPoolExecutor")
    public ThreadPoolExecutor flushBillThreadPoolExecutor() {
        return new ThreadPoolExecutor(
                8,
                16,
                60,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }


    /**
     * 用于对账时将拉取的50000条关联记录执行对账。
     * CPU密集型，小线程池。
     */
    @Bean("executeJoinReconciliationThreadPoolExecutor")
    public ThreadPoolExecutor executeJoinReconciliationThreadPoolExecutor() {
        return new ThreadPoolExecutor(
                5,
                9,
                60,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }
}
